#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		int a[m];
		for(int i = 0;i<m;i++)
			scanf("%d",&a[i]);
		sort(a,a+m);
		int ans = 1000;
		for(int i = 0;i<m-n+1;i++)
		{
		//	printf("%d\n",a[i]);
			int f = a[i+n-1]-a[i];
		//	printf("%d\n",m);
			ans = min(ans,f);
		}
		printf("%d\n",ans);
	}
}
